fix: MoLang optimization quick-fix range resolution to prevent malformed rewrites#497
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/Blockception/minecraft-bedrock-language-server/sessions/d914919e-9ee9-4159-bd53-c8cd963e5566 Co-authored-by: DaanV2 <2393905+DaanV2@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix molang rewrite for math constants
Fix MoLang optimization quick-fix range resolution to prevent malformed rewrites
May 15, 2026
DaanV2
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MoLang optimization diagnostics were generating correct replacement text (
math.pino longermath.pi()), but quick-fix application still used an incorrect edit range in some cases. This caused partial-token replacement and corrupted output such as5*3(math.pi() * 15).pi.Root cause
diag.range, which could point to an inner/misaligned span instead of the full expression intended for rewrite.Diagnostic payload now carries source offsets
packages/bedrock-diagnoser/src/diagnostics/molang/optimizations/registry.tsstartOffsetandendOffsetto optimization diagnosticdatawhen areplacementis present.Code action now prefers offset-derived range
ide/base/server/src/lsp/code-action/minecraft/molang/optimization.tseditRangefromstartOffset/endOffsetwhen available; falls back todiag.rangefor compatibility.5*3*math.pi) rather than a partial segment.Regression coverage
ide/base/server/src/lsp/code-action/minecraft/molang/optimization.test.tsdiag.rangedoes not affect replacement when offsets are present.5*3*math.piregression path:packages/bedrock-diagnoser/test/lib/diagnostics/molang/optimizations.test.ts